package com.qianfeng.wuyang.himalaya.adapter.monthlyadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qianfeng.wuyang.himalaya.R;
import com.qianfeng.wuyang.himalaya.bean.monthlybean.MonthlyEntity;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2016/12/6.
 */

public class AnchorMonthlyAdapter extends RecyclerView.Adapter<AnchorMonthlyAdapter.ViewHolder>{
    private Context context;
    private List<MonthlyEntity.DatasBean.ListBean> list;
    public AnchorMonthlyAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_monthly,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.item_monthly_title.setText(list.get(position).getTitle());
        holder.item_monthly_firstKResults_title1.setText("1   "+list.get(position).getFirstKResults().get(0).getTitle());
        holder.item_monthly_firstKResults_title2.setText("2   "+list.get(position).getFirstKResults().get(1).getTitle());
        Picasso.with(context).load(list.get(position).getCoverPath()).into(holder.item_monthly_img);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public void addAll(Collection<? extends MonthlyEntity.DatasBean.ListBean>collection){
        int size = list.size();
        list.addAll(collection);
        notifyItemRangeInserted(size,collection.size());
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        private ImageView item_monthly_img;
        private TextView item_monthly_title,item_monthly_firstKResults_title1,item_monthly_firstKResults_title2;
        public ViewHolder(View itemView) {
            super(itemView);
            item_monthly_img = (ImageView) itemView.findViewById(R.id.item_monthly_coverPath);
            item_monthly_title = (TextView) itemView.findViewById(R.id.item_monthly_title);
            item_monthly_firstKResults_title1 = (TextView) itemView.findViewById(R.id.item_monthly_firstKResults_title1);
            item_monthly_firstKResults_title2 = (TextView) itemView.findViewById(R.id.item_monthly_firstKResults_title2);
        }
    }
}
